package android.BigCity;

import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import android.activity.R;
/*
 * klasa so koja se kreira pocetniot ekran
 * koj sodrzi lista na lekcii za ucenje
 * pri sto so klik na edna od niv, korisnikot se 
 * prenasocuva kon naredniot ekran
 */
public class BigCitySmallWorldActivity extends ListActivity{
	/*
	 * klasa vo koj se kreira listata na epizodi(lekcii) pri sto osven naslovot
	 * se kreira i soodvetna ikona za sekoj element od listata posebno
	 */
	public class MyCustomAdapter extends ArrayAdapter<String> {
	
	public MyCustomAdapter(Context context, int textViewResourceId,String[] objects) {
			super(context, textViewResourceId, objects);
			// TODO Auto-generated constructor stub
			}

			@Override
			public View getView(int position, View convertView, ViewGroup parent) {
			
			LayoutInflater inflater = getLayoutInflater();
			View row = inflater.inflate(R.layout.row, parent, false);
			TextView label = (TextView)row.findViewById(R.id.lblEp);
			label.setText(items[position]);
			ImageView icon = (ImageView)row.findViewById(R.id.icon);

			if (items[position].equals("Episode 1 - Nice to meet you")){
			icon.setImageResource(R.drawable.icon1);
			}
			else if (items[position].equals("Episode 2 - Get a piece of the action")){
			icon.setImageResource(R.drawable.icon2);
			}
			else if (items[position].equals("Episode 3 - I have been kicked out")){
				icon.setImageResource(R.drawable.icon3);
				}
			else if (items[position].equals("Episode 4 - We have a mission")){
				icon.setImageResource(R.drawable.icon4);
				}
			else if (items[position].equals("Episode 5 - Why are you looking so glum?")){
				icon.setImageResource(R.drawable.icon5);
				}
			else if (items[position].equals("Episode 6 - He is a pest")){
				icon.setImageResource(R.drawable.icon6);
				}		

			return row;
			}
	}
		
	String[] items;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
       items = getResources().getStringArray(R.array.titles);
       setListAdapter(new MyCustomAdapter(BigCitySmallWorldActivity.this, R.layout.row, items));
       
    }
    /*
     * funkcija za povikuvanje na nastan koga ke se klikne na nekoj element od listata
     * korisnikot se prenasocuva na nov ekran pri sto se
     * zacuvuvaat i prenesuvaat informacii za toa koja epizoda e izbrana
     * i vrz osnova na toa se prikazuva soodvetnata sodrzina
     */
    @Override
	public void onListItemClick(ListView l, View v, int position, long id) {
		// TODO Auto-generated method stub
    	
    	Intent show = new Intent(getApplicationContext(),Lekcija.class);
    	Bundle extras = new Bundle();
		extras.putString("ime", items[position]);
		show.putExtras(extras);
    	startActivity(show);
    	
		super.onListItemClick(l, v, position, id);
		
	}
}